/**
 * 
 */
package com.gragra.stats;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.util.Map;
import java.util.TreeMap;
/**
 * @author Christoph Teichmann
 * 16.06.2013
 */
public class SortLinesForFirstNumber
{
	public static void main(String... args) throws IOException
	{
		BufferedReader br = new BufferedReader(new FileReader(args[0]));
		TreeMap<Integer, String> map = new TreeMap<Integer, String>();
		String line;
		while((line = br.readLine()) != null)
		{
			line = line.trim();
			map.put(Integer.parseInt(line.split("\\s+")[0]), line);
		}
		br.close();
		boolean first = true;
		BufferedWriter bw = new BufferedWriter(new FileWriter(args[1]));
		for(Map.Entry<Integer, String> ent : map.entrySet())
		{
			if(first)
			{first = false;}
			else
			{bw.newLine();}
			bw.write(ent.getValue());
		}
		bw.close();
	}
}